﻿package Socket
{
	import flash.utils.ByteArray;
	import flash.net.Socket;
	import flashx.textLayout.elements.Configuration;
	import Utils.*;

	public class ActionSender extends Contexted
	{
		private var socket:Socket;
		public var key:BindableUnsignedInteger;

		public function ActionSender(context:Context)
		{
			super(context);
			this.socket = context.connection.socket;
			key = new BindableUnsignedInteger();
		}

		public function onMoveAvatar(direction:uint)
		{
			trace("Moving avatar");
			socket.writeByte(Headers.Move);
			socket.writeUnsignedInt(direction);
			socket.flush();
		}

		public function onSendKey()
		{
			trace("Sending Key");
			socket.writeByte(Headers.SendKey);
			socket.writeUnsignedInt(key.data);
			socket.flush();
		}

		public function onReady()
		{
			trace("Im Ready");
			socket.writeByte(Headers.Ready);
			socket.flush();
		}

		public function onPutBomb()
		{
			trace("I put a bomb");
			socket.writeByte(Headers.PutBomb);
			socket.flush();
		}

		public function onTriggerBomb()
		{
			trace("I trigger the bomb");
			socket.writeByte(Headers.TriggerBomb);
			socket.flush();
		}
	}

}